﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FacialClub.Helpers
{
    /// <summary>
    /// View Data Extension
    /// </summary>
    public static class ViewDataExtensions
    {
        /// <summary>
        /// ViewData
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static IEnumerable<T> ViewData<T>(this HtmlHelper helper, string name)
        {
            if (helper.ViewData[name] != null)
            {
                return (IEnumerable<T>)helper.ViewData[name];
            }
            return new List<T>();
        }

        /// <summary>
        /// View Data Single
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T ViewDataSingle<T>(this HtmlHelper helper, string name)
        {
            if (helper.ViewData[name] != null)
            {
                return (T) helper.ViewData[name];
            }
            return default(T);
        }
    }
}